package alfred.mdp.tsp.worker;

import alfred.mdp.messages.ProtocolMessage;
import alfred.mdp.tsp.Titanic;
import alfred.mdp.worker.WorkerService;
import alfred.storage.Storage;
import org.zeromq.ZFrame;
import org.zeromq.ZMsg;

/**
 */
public class CloseWorker extends WorkerService {
    private final Storage<ZFrame, ZMsg> storage;

    public CloseWorker(Storage storage) {
        this.storage = storage;
    }

    @Override
    public ZMsg process(ZMsg input) {
        ZFrame uuid = ProtocolMessage.get(input, 0);
        if (storage.remove(uuid)) {
            //todo:log???
        }
        ZMsg result = new ZMsg();
        result.addLast(Titanic.ResponseCode.OK);
        result.addLast(uuid);
        return result;
    }

    @Override
    public String getName() {
        return Titanic.TITANIC_CLOSE_SERVICE;
    }
}
